package com.example.shiroredis.entity.base;

/**
 * @Author: hwz
 * @Date: 2018/6/25
 */
public enum ResultCode {

    CODE_OK(ServiceCode.OK,"成功"),
    CODE_USER_EXCEPTION(ServiceCode.USER_EXCEPTION,"用户不存在"),
    CODE_NOT_LOGIN(ServiceCode.NOT_LOGIN,"用户未登录"),
    CODE_EXCEPTION(ServiceCode.EXCEPTION,"内部出现错误"),
    CODE_PARAM_ERROR(ServiceCode.PARAM_ERROR,"请求参数错误"),
    CODE_NO_DATA(ServiceCode.NO_DATA,"数据查找失败"),
    CODE_TIMEOUT(ServiceCode.TIMEOUT,"请求超时,请稍后再试"),
    CODE_DATABASE_ERROR(ServiceCode.DATABASE_ERROR,"数据异常"),
    CODE_UNKNOWN_ERROR(ServiceCode.UNKNOWN_ERROR,"未知错误"),
    CODE_NO_HEAD_TOKEN_ERROR(ShiroJwtCode.NO_HEAD_TOKEN_ERROR,"头部没有token"),
    CODE_EXPIRE_TIME_ERROR(ShiroJwtCode.EXPIRE_TIME_ERROR,"Token过期"),
    CODE_DECODE_ERROR(ShiroJwtCode.DECODE_ERROR,"token验证不通过"),
    CODE_NO_SESSIONID_TOKEN_ERROR(ShiroJwtCode.NO_SESSIONID_TOKEN_ERROR,"token中并没有sessionId信息");

    private int code;
    private String desc;

    ResultCode(int code, String desc){
        this.code = code;
        this.desc = desc;
    }

    public int getCode(){
        return code;
    }
    public String getDesc(){
        return desc;
    }

    public static ResultCode valueOf(int code){

        switch (code){
            case ServiceCode.OK:
                return CODE_OK;
            case ServiceCode.EXCEPTION:
                return CODE_EXCEPTION;
            case ServiceCode.DATABASE_ERROR:
                return CODE_DATABASE_ERROR;
            case ServiceCode.NO_DATA:
                return CODE_NO_DATA;
            case ServiceCode.PARAM_ERROR:
                return CODE_PARAM_ERROR;
            case ServiceCode.TIMEOUT:
                return CODE_TIMEOUT;
            case ServiceCode.UNKNOWN_ERROR:
                return CODE_UNKNOWN_ERROR;
            case ServiceCode.USER_EXCEPTION:
                return CODE_USER_EXCEPTION;
            default:
                return CODE_UNKNOWN_ERROR;
        }

    }

}
